package quizman;
import java.util.List;

import quizman.domain.Choice;
import quizman.domain.MultipleChoiceQuestion;
import quizman.domain.NumericQuestion;
import quizman.domain.Question;
import quizman.domain.Quiz;
import quizman.domain.ShortAnswerQuestion;
import quizman.mappers.QuizMapper;


public class QuizTest {
	public static void main(String[] args) {
		try {
			Quiz quiz = QuizMapper.find("TesterQuiz");
			System.out.println("Name of Quiz: " + quiz.getName());
			List<Question> a = quiz.getQuestions();
			for(Question q : a) {
				String thisClass = q.getClass().toString();
				System.out.println("Question Name: " + q.getName());
				System.out.println("Question Text: " + q.getText());
				if(thisClass.contains("MultipleChoiceQuestion")) {
					List<Choice> l = ((MultipleChoiceQuestion) q).getChoices();
					int questionNumber = 1;
					int rightAnswer = 0;
					for(Choice c : l) {
						System.out.println(questionNumber++ + ") " + c.getText());
						if(c.isCorrect()) rightAnswer = questionNumber - 1;
					}
					System.out.println("The correct answer is: (" + rightAnswer + ")");
				}
				else if(thisClass.contains("NumericQuestion")) {
					System.out.println("Lower Bound: " + ((NumericQuestion) q).getLowerBound());
					System.out.println("Upper Bound: " + ((NumericQuestion) q).getUpperBound());
				}
				else if(thisClass.contains("ShortAnswerQuestion")) {
					System.out.println("Answer: " + ((ShortAnswerQuestion) q).getAnswer());
				}
				else System.out.println(q.getClass());
				
				System.out.println();
			}
			List<Quiz> lq = QuizMapper.findAll();
			System.out.println("\n*QUIZ NAMES*");
			for(Quiz q : lq) {
				System.out.println(q.getName());
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
}
